package com.geepi.soundcloud.controller.util;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;

public class ObjectMappingCustomer extends ObjectMapper {
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public ObjectMappingCustomer () {
        super ();
        // 空值处理为空串
        this.getSerializerProvider ().setNullValueSerializer (new JsonSerializer <Object> () {
            @Override
            public void serialize (Object value, JsonGenerator gen,
                                   SerializerProvider serializers) throws IOException, JsonProcessingException {
                gen.writeString ("");
            }
        });

        // allow JSON empty String value ("") to be bound to POJOs as null
        this.enable (DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);

    }
}
